package com.houweishi.module.reimburse.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.currency.controller.OaCurrencyController;
import com.houweishi.module.reimburse.domain.OaReimburse;
import com.houweishi.module.reimburse.domain.OaReimburseApproval;
import com.houweishi.module.reimburse.service.IOaReimburseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报销单管理Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/reimburse")
public class OaReimburseController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(OaCurrencyController.class);
    @Autowired
    private IOaReimburseService oaReimburseService;

    /**
     * 查询报销单管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaReimburse oaReimburse)
    {
        startPage();
        List<OaReimburseApproval> list = oaReimburseService.selectOaReimburseApprovalList(oaReimburse);
        return getDataTable(list);
    }

    /**
     * 导出报销单管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:export')")
    @Log(title = "报销单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaReimburse oaReimburse)
    {
        List<OaReimburse> list = oaReimburseService.selectOaReimburseList(oaReimburse);
        ExcelUtil<OaReimburse> util = new ExcelUtil<OaReimburse>(OaReimburse.class);
        util.exportExcel(response, list, "报销单管理数据");
    }

    /**
     * 获取报销单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:query')")
    @GetMapping(value = "/{reimburseId}")
    public AjaxResult getInfo(@PathVariable("reimburseId") Long reimburseId)
    {
        return success(oaReimburseService.selectOaReimburseByReimburseId(reimburseId));
    }

    /**
     * 新增报销单管理
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:add')")
    @Log(title = "报销单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaReimburse oaReimburse)
    {
        try {
            return oaReimburseService.insertOaReimburse(oaReimburse);
        } catch (Exception e) {
            LOGGER.error("新增报销单管理失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改报销单管理
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:edit')")
    @Log(title = "报销单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaReimburse oaReimburse)
    {
        return toAjax(oaReimburseService.updateOaReimburse(oaReimburse));
    }

    /**
     * 删除报销单管理
     */
    @PreAuthorize("@ss.hasPermi('module:reimburse:remove')")
    @Log(title = "报销单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reimburseIds}")
    public AjaxResult remove(@PathVariable Long[] reimburseIds)
    {
        return toAjax(oaReimburseService.deleteOaReimburseByReimburseIds(reimburseIds));
    }
}
